package com.ylx.web.y;

import com.alibaba.fastjson.JSON;
import com.ylx.pojo.Order;
import com.ylx.service.OrderService;
import com.ylx.service.OrderServiceImpl;
import com.ylx.service.UserService;
import com.ylx.service.UserServiceIpml;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/selectServlet")
public class SelectServlet extends HttpServlet {
    private OrderService orderService=new OrderServiceImpl();
    private UserService userService=new UserServiceIpml();
    protected void doPost (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        List<Order> allOrderList = orderService.getAllOrderList();



        for (int i = 0; i < allOrderList.size(); i++) {


            Order order = allOrderList.get(i);

            String jsonString= JSON.toJSONString(order);

            response.setContentType("text/json;charset=utf-8");
            response.getWriter().write(jsonString);
        }



    }

    protected void doGet (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doPost(request, response);

    }
}

